//
//  TKL_blogCircleVC.m
//  TKL_EnPro
//
//  Created by 雅恩三河科技 on 2018/12/7.
//  Copyright © 2018年 MrZhang. All rights reserved.
//

//
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//                  \./                  \\`.
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
//
//

#import "TKL_blogCircleVC.h"
#import "TKL_BlogCircleViewModel.h"
#import "TKL_CicleCell.h"
#import "TKL_addBlogVC.h"
#import "TKL_BLogDetailVC.h"
@interface TKL_blogCircleVC ()
{
    NSInteger currentPage;
}
@property(nonatomic,strong)TKL_BlogCircleViewModel* viewModel;
@property(nonatomic,strong)NSMutableArray* dataSource;
@end

@implementation TKL_blogCircleVC
-(NSMutableArray *)dataSource
{
    if (!_dataSource) {
        _dataSource=[NSMutableArray new];
    }
    return _dataSource;
}
-(TKL_BlogCircleViewModel *)viewModel
{
    if (!_viewModel) {
        _viewModel=[TKL_BlogCircleViewModel new];
    }
    return _viewModel;
}
#pragma mark - event
#pragma mark - method
-(void)initilization
{
    self.isGroup = YES;
    currentPage=1;
    @WeakSelf;
    self.navigationItem.title =@"婚礼圈";
    [self setRightBarButtonWithTitle:@"发布" titleColor:HEXCOLOR(@"#666666") withBlock:^{
        if ([TKL_LoginViewModel shareInterface].isLogin)
        {
            TKL_addBlogVC* vc=[[TKL_addBlogVC alloc] init];
            [selfp.navigationController pushViewController:vc animated:YES];
        }else
        {
            [[GCPresenter shareInterface]loadLogin];;
        }
    }];
    self.extendedLayoutIncludesOpaqueBars = YES;
    self.baseTable.contentInset = UIEdgeInsetsMake([self topShelterHeight], 0, [self bottomShelterHeight], 0);
    self.view.backgroundColor = Main_Color_BG;
    self.navigationController.navigationBar.shadowImage = [[UIImage new]rt_darkenWithLevel:0.1f];
    
    [self.view addSubview:self.baseTable];
    [self.baseTable setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.baseTable setSeparatorColor:Main_Color_BG];
    [self viewModelBand];
    
    self.baseTable.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        currentPage=1;
        [selfp reloadData];
         [selfp.baseTable.mj_header endRefreshing];
    }];
    self.baseTable.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
        currentPage+=1;
        [selfp reloadData];
        [selfp.baseTable.mj_footer endRefreshing];
    }];
    [selfp reloadData];
}
-(void)viewModelBand
{
    @WeakSelf;
    GCBaseObservationModel* saleOber1=[GCBaseObservationModel new];
    saleOber1.keyPath=@"itemArr";
    saleOber1.observation=self.viewModel;
    saleOber1.handler = ^(NSString *keyPath) {
        [selfp.baseTable reloadData];
    };
    [self registObservation:saleOber1];
    
    GCBaseObservationModel* saleOber2=[GCBaseObservationModel new];
    saleOber2.keyPath=@"datas";
    saleOber2.observation=self.viewModel;
    saleOber2.handler = ^(NSString *keyPath) {
        [selfp.baseTable reloadData];;
    };
    [self registObservation:saleOber2];
    
    GCBaseObservationModel* saleOber3=[GCBaseObservationModel new];
    saleOber3.keyPath=@"beautyArr";
    saleOber3.observation=self.viewModel;
    saleOber3.handler = ^(NSString *keyPath) {
        [selfp.baseTable reloadData];
    };
    [self registObservation:saleOber3];
}
-(void)reloadListData
{
    NSMutableDictionary* para=[NSMutableDictionary new];
    
    [para setObject:[NSNumber numberWithInteger:currentPage] forKey:@"page"];
    if (currentPage==1)
    {
        [para setObject:@"0" forKey:@"base"];
    }else
    {
        [para setObject:[NSNumber numberWithInteger:[[WFFunctions getStringNow] integerValue]*1000] forKey:@"base"];
    }
    [self requestCityData:para];
}
-(void)reloadData
{
    [self reloadListData];
}
-(void)reloadView
{
    
}
#pragma mark - life

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initilization];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.dataSource.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    @WeakSelf;
    static NSString* identify=@"PPthreePhonecell";
    TKL_CicleCell* cell=[tableView dequeueReusableCellWithIdentifier:identify];
    if (!cell) {
        cell=[[TKL_CicleCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identify];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.backgroundColor=[UIColor whiteColor];
    }
    NSDictionary* dic=self.dataSource[indexPath.section];
    cell.height=WFCGFloatY(340);
    [cell setSourceDic:selfp.dataSource[indexPath.section]];

    [cell.imageScroll addTapGestureRecognizerWithDelegate:self Block:^(NSInteger tag) {
        
        TKL_BLogDetailVC* mm=[[TKL_BLogDetailVC alloc] init];
        mm.blogID=[NSString stringWithFormat:@"%@",[dic objectForKey:@"id"]];
        mm.cityID=[NSString stringWithFormat:@"%@",[dic objectForKey:@"cid"]];
        [selfp.navigationController pushViewController:mm animated:YES];
    }];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return WFCGFloatY(320);
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView* view=[[UIView alloc] init];
    view.backgroundColor=[UIColor whiteColor];
    
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return .0001f;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView* view=[UIView new];
    view.backgroundColor=Main_Color_BGLightGray;
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return WFCGFloatY(10);
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary* dic=self.dataSource[indexPath.section];
    TKL_BLogDetailVC* mm=[[TKL_BLogDetailVC alloc] init];
    mm.blogID=[NSString stringWithFormat:@"%@",[dic objectForKey:@"uuid"]];
    mm.cityID=[NSString stringWithFormat:@"%@",[dic objectForKey:@"cid"]];
    [self.navigationController pushViewController:mm animated:YES];
}

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
}
-(void)requestCityData:(NSMutableDictionary *)para
{
    @WeakSelf;
    //http://discover.hunlimao.com/topic/index?cid=0&page=1
    [[InterfaceManager shareInterface] requestAllInterface:@"http://101.201.171.131:8080/rest/api/community/poster/list" para:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        if (currentPage==1) {
            [selfp.dataSource removeAllObjects];
        }
        NSArray* arr=[info objectForKey:@"dataList"];
        for (NSDictionary* dic in arr) {

            if ([[dic objectForKey:@"longShort"] integerValue]==1)
            {
                 [selfp.dataSource addObject:dic];
            }
        }
        [selfp.baseTable reloadData];
    }];
   // 1544683517694
}
@end


/*
 11111111111111111111111111111111111111001111111111111111111111111
 11111111111111111111111111111111111100011111111111111111111111111
 11111111111111111111111111111111100001111111111111111111111111111
 11111111111111111111111111111110000111111111111111111111111111111
 11111111111111111111111111111000000111111111111111111111111111111
 11111111111111111111111111100000011110001100000000000000011111111
 11111111111111111100000000000000000000000000000000011111111111111
 11111111111111110111000000000000000000000000000011111111111111111
 11111111111111111111111000000000000000000000000000000000111111111
 11111111111111111110000000000000000000000000000000111111111111111
 11111111111111111100011100000000000000000000000000000111111111111
 11111111111111100000110000000000011000000000000000000011111111111
 11111111111111000000000000000100111100000000000001100000111111111
 11111111110000000000000000001110111110000000000000111000011111111
 11111111000000000000000000011111111100000000000000011110001111111
 11111110000000011111111111111111111100000000000000001111100111111
 11111111000001111111111111111111110000000000000000001111111111111
 11111111110111111111111111111100000000000000000000000111111111111
 11111111111111110000000000000000000000000000000000000111111111111
 11111111111111111100000000000000000000000000001100000111111111111
 11111111111111000000000000000000000000000000111100000111111111111
 11111111111000000000000000000000000000000001111110000111111111111
 11111111100000000000000000000000000000001111111110000111111111111
 11111110000000000000000000000000000000111111111110000111111111111
 11111100000000000000000001110000001111111111111110001111111111111
 11111000000000000000011111111111111111111111111110011111111111111
 11110000000000000001111111111111111100111111111111111111111111111
 11100000000000000011111111111111111111100001111111111111111111111
 11100000000001000111111111111111111111111000001111111111111111111
 11000000000001100111111111111111111111111110000000111111111111111
 11000000000000111011111111111100011111000011100000001111111111111
 11000000000000011111111111111111000111110000000000000011111111111
 11000000000000000011111111111111000000000000000000000000111111111
 11001000000000000000001111111110000000000000000000000000001111111
 11100110000000000001111111110000000000000000111000000000000111111
 11110110000000000000000000000000000000000111111111110000000011111
 11111110000000000000000000000000000000001111111111111100000001111
 11111110000010000000000000000001100000000111011111111110000001111
 11111111000111110000000000000111110000000000111111111110110000111
 11111110001111111100010000000001111100000111111111111111110000111
 11111110001111111111111110000000111111100000000111111111111000111
 11111111001111111111111111111000000111111111111111111111111100011
 11111111101111111111111111111110000111111111111111111111111001111
 11111111111111111111111111111110001111111111111111111111100111111
 11111111111111111111111111111111001111111111111111111111001111111
 11111111111111111111111111111111100111111111111111111111111111111
 11111111111111111111111111111111110111111111111111111111111111111
 
 
 */
